package com.zzyl.controller.web;

import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.Floor;
import com.zzyl.entity.Room;
import com.zzyl.service.RoomService;
import com.zzyl.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoomController extends BaseController {
    @Autowired
    private RoomService roomService;


    //新增房间
    @PostMapping("/room/add")
    public ResponseResult save(@RequestBody Room room){
        roomService.saveOrUpdateRoom(room);
        return success();
    }

    //查询指定的各楼层下的房间
    @GetMapping("/room/getRoomsByFloorId/{floorId}")
    public ResponseResult findByFloorId(@PathVariable Long floorId){
        List<RoomVo> list = roomService.findByFloorId(floorId);
        return success(list);
    }

    //查询房间详情
    @GetMapping("/room/get/{id}")
    public ResponseResult findById(@PathVariable Long id){
        RoomVo roomVo = roomService.findRoomById(id);
        return success(roomVo);
    }

    //更新房间
    @PutMapping("/room/update")
    public ResponseResult update(@RequestBody Room room){
        roomService.saveOrUpdateRoom(room);
        return success();
    }

    //删除房间
    @DeleteMapping("/room/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        roomService.removeById(id);
        return success();
    }
}
